package com.cy.detectsys.controller.detect.node;

import com.cy.detectsys.entity.ProxynodeResource;
import com.cy.detectsys.model.PageDto;
import com.cy.detectsys.model.PageReqModel;
import com.cy.detectsys.service.ProxynodeResourceService;
import com.cy.detectsys.util.R;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("proxynode")
public class ProxyNodeController {

    @Resource
    private ProxynodeResourceService baseService;

    @RequestMapping("add")
    public R add(@RequestBody ProxynodeResource proxynodeResource) {
        baseService.save(proxynodeResource);
        return R.ok(proxynodeResource);
    }
    @RequestMapping("update")
    public R update(@RequestBody ProxynodeResource proxynodeResource) {
        baseService.updateById(proxynodeResource);
        return R.ok(proxynodeResource);
    }

    @RequestMapping("delete")
    public R delete(@RequestBody ProxynodeResource proxynodeResource) {
        baseService.removeById(proxynodeResource);
        return R.ok(proxynodeResource);
    }

    @RequestMapping("list")
    public R list(@RequestBody PageReqModel<ProxynodeResource> form) {
        PageHelper.startPage(form.getPage(), form.getPageSize());
        List<ProxynodeResource> list = baseService.list();
        return R.ok(PageDto.listToPageDto(list));
    }

}
